(next-line): Move error signaling and special end of
authorRichard M. Stallman <rms@gnu.org>
Wed, 26 Jan 1994 17:19:32 +0000 (17:19 +0000)
committerRichard M. Stallman <rms@gnu.org>
Wed, 26 Jan 1994 17:19:32 +0000 (17:19 +0000)
line behavior into line-move so that next-line is symmetric with
previous-line when next-line-add-newlines is nil.

(line-move): Move as far as possible and ding with a message
if the requested motion cannot be accomplished.  When
selective-display is numeric, ensure point actually moves and does
so to a visible line.

lisp/simple.el

index 461ee1e92e03cf890f72b0c41f50911d6c548cb2..fc4ac793eabc550f1d904d1ad6b14e056764f53e 100644 (file)
@@ -1413,20 +1413,14 @@ If you are thinking of using this in a Lisp program, consider
 using `forward-line' instead.  It is usually easier to use
 and more reliable (no dependence on goal column, etc.)."
   (interactive "p")
-  (let ((opoint (point)))
-    (if next-line-add-newlines
-       (if (/= arg 1)
-           (line-move arg)
-         (forward-line 1)
-         (if (or (= opoint (point)) (not (eq (preceding-char) ?\n)))
-             (insert ?\n)
-           (goto-char opoint)
-           (line-move arg)))
-      (if (eobp)
-         (signal 'end-of-buffer nil))
-      (line-move arg)
-      (if (= opoint (point))
-         (end-of-line))))
+  (if (and next-line-add-newlines (= arg 1))
+      (let ((opoint (point)))
+       (forward-line 1)
+       (if (or (= opoint (point)) (not (eq (preceding-char) ?\n)))
+           (insert ?\n)
+         (goto-char opoint)
+         (line-move arg)))
+    (line-move arg))
   nil)
 
 (defun previous-line (arg)
@@ -1462,29 +1456,43 @@ at the start of current run of vertical motion commands.
 When the `track-eol' feature is doing its job, the value is 9999.")
 
 (defun line-move (arg)
-  (if (not (or (eq last-command 'next-line)
-              (eq last-command 'previous-line)))
-      (setq temporary-goal-column
-           (if (and track-eol (eolp)
-                    ;; Don't count beg of empty line as end of line
-                    ;; unless we just did explicit end-of-line.
-                    (or (not (bolp)) (eq last-command 'end-of-line)))
-               9999
-             (current-column))))
-  (if (not (integerp selective-display))
-      (forward-line arg)
-    ;; Move by arg lines, but ignore invisible ones.
-    (while (> arg 0)
-      (vertical-motion 1)
-      (forward-char -1)
-      (forward-line 1)
-      (setq arg (1- arg)))
-    (while (< arg 0)
-      (vertical-motion -1)
-      (beginning-of-line)
-      (setq arg (1+ arg))))
-  (move-to-column (or goal-column temporary-goal-column))
-  nil)
+  (let ((signal
+        (catch 'exit
+          (if (not (or (eq last-command 'next-line)
+                       (eq last-command 'previous-line)))
+              (setq temporary-goal-column
+                    (if (and track-eol (eolp)
+                             ;; Don't count beg of empty line as end of line
+                             ;; unless we just did explicit end-of-line.
+                             (or (not (bolp)) (eq last-command 'end-of-line)))
+                        9999
+                      (current-column))))
+          (if (not (integerp selective-display))
+              (or (and (zerop (forward-line arg))
+                       (bolp))
+                  (throw 'exit (if (bobp)
+                                   'beginning-of-buffer
+                                 'end-of-buffer)))
+            ;; Move by arg lines, but ignore invisible ones.
+            (while (> arg 0)
+              (end-of-line)
+              (and (zerop (vertical-motion 1))
+                   (throw 'exit 'end-of-buffer))
+              (setq arg (1- arg)))
+            (while (< arg 0)
+              (beginning-of-line)
+              (and (zerop (vertical-motion -1))
+                   (throw 'exit 'beginning-of-buffer))
+              (setq arg (1+ arg))))
+          (move-to-column (or goal-column temporary-goal-column))
+          nil)))
+    (cond
+     ((eq signal 'beginning-of-buffer)
+      (message "Beginning of buffer")
+      (ding))
+     ((eq signal 'end-of-buffer)
+      (message "End of buffer")
+      (ding)))))
 
 ;;; Many people have said they rarely use this feature, and often type
 ;;; it by accident.  Maybe it shouldn't even be on a key.